import com.troyworks.events.TProxy;
import com.troyworks.framework.logging.SOSLogger;
import com.troyworks.util.DesignByContract;
/**
 * A utilty to test the TProxy delegate replacement
 * that accepts additional parameters
 * 
 * FLASH IDE:
 * import com.troyworks.events.TestTProxy;
   TestTProxy.main(this);
  
 * @author Troy Gardner
 */
class com.troyworks.events.TestTProxy extends DesignByContract {
	public static var _libSOS:Function = SOSLogger;
	public function TestTProxy() {
		super();
		var o:Object = new Object();
		o.callback = function():String{
			var res:String = "** CallBack1 **\r"+arguments.join("\r");
			//trace(res);
			return res;
		};
		var o2:Object = new Object();
		o2.callback = function():String{
				var res:String = "** CallBack2 **\r"+arguments.join("\r");
			//	trace(res);
				return res;
		};
		// create the proxy with user supplied arguments
		TProxy.currentUserName = "TestTProxy";
		var f:Function = TProxy.create(o, o.callback, "UsrA", "UsrB");
		var f2:Function = TProxy.create(o2, o2.callback);
		var f3:Function = TProxy.create(o2,o2.callback);
		TProxy.currentUserName = null;
		
		trace(util.Trace.me(f, " TProxy's id's", false));
		//broadcast the real events.
		/////////////////////TEST1 ////////////////////////////////
		var t1:String= "** CallBack1 **\r";
		t1+="UsrA\r";
		t1+="UsrB\r";
		t1+="[type Function]";
		
		 ASSERT_TEST(f(), IS_EQUAL, t1, "f()","text1", "TestTProxy.Test1 FAILED");
			 
		 //////////////////////TEST2 ////////////////////////////////
		var t2:String= "** CallBack2 **\r";
		t2+="[type Function]";
		
		 ASSERT_TEST(f2(), IS_EQUAL, t2, "f2()","text2", "TestTProxy.Test2 FAILED");
		 //////////////////////TEST2b ////////////////////////////////
		var t2b:String= "** CallBack2 **\r ";
		
		 ASSERT_TEST(f3(), IS_EQUAL, t2b, "f3()","text2b", "TestTProxy.Test2b FAILED");
	
		 ////////////////////TEST3 ////////////////////////////////
		var t3:String= "** CallBack1 **\r";
		t3+="RealA\r";
		t3+="RealB\r";
		t3+="RealC\r";
		t3+="RealD\r";
		t3+="UsrA\r";
		t3+="UsrB\r";
		t3+="[type Function]";

		 ASSERT_TEST(f("RealA","RealB","RealC","RealD"), IS_EQUAL, t3, "f()","text3", "TestTProxy Test3 FAILED");
		
		////////////////////TEST4 ////////////////////////////////
		var t4:String= "** CallBack2 **\r";
		t4+="RealA\r";
		t4+="RealB\r";
		t4+="RealC\r";
		t4+="RealD\r";
		t4+="[type Function] ";
		
		ASSERT_TEST(f2("RealA","RealB","RealC","RealD"), IS_EQUAL, t4, "f()","text4", "TestTProxy Test4 FAILED");
		
		////////TEST END///////////////////
		passedAllTests();
		return;
	}
	public function passedAllTests():Void{
		trace("com.troyworks.events.TestTProxy PASSED ALL TESTS :):):):):):):):):):):):):):):):)");
	}
	
	public static function main(container : MovieClip) : Void {
		trace("TestTProxy main");
		var t:TestTProxy = new TestTProxy();
	}
}